<template>
  <div class="admin-comment">
    <div class="my-admin-header">
      <div class="left">
        <h1 class="title">
          <i class="el-icon-video-camera-solid"></i>
          视频管理
        </h1>
      </div>
    </div>
    <div class="my-admin-content">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="userName" label="用户名" width="180">
          <template slot-scope="scope">
            <router-link
              :to="{name:'personPage',query:{id:scope.row.userId}}"
            >{{scope.row.userName}}</router-link>
          </template>
        </el-table-column>
        <el-table-column prop="title" label="视频" width="180">
          <template slot-scope="scope">
            <router-link :to="{name:'play',query:{id:scope.row.id}}">{{scope.row.title}}</router-link>
          </template>
        </el-table-column>
        <el-table-column prop="uploadTime" label="时间" width="180"></el-table-column>
        <!--  <el-table-column prop="content" label="内容" width="180"></el-table-column> -->
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.$index, scope.row,0)"
              v-if="scope.row.state==1"
            >删除</el-button>
            <el-button
              size="mini"
              type="success"
              @click="handleDelete(scope.$index, scope.row,1)"
              v-if="scope.row.state==0"
            >恢复</el-button>

            <el-button
              size="mini"
              type="primary"
              @click="cState(scope.$index, scope.row,1)"
              v-if="scope.row.checkState==0"
            >通过审核</el-button>
            <el-button
              size="mini"
              type="success"
              @click="cState(scope.$index, scope.row,0)"
              v-if="scope.row.checkState==1"
            >已通过</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <ElPagination :total="totalRow" :current-page.sync="pageNumber" :page-size="8" background></ElPagination>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "admin-user",
  data: function() {
    return {
      tableData: [],
      checkState: ["未审核", "通过", "不通过"],
      pageNumber: 1,
      pageSize: 8,
      totalRow: 0,
      userName: "",
      title: ""
    };
  },
  methods: {
    handleDelete(index, obj, state) {
      this.axios
        .post("admin/videoState", {
          id: obj.id,
          state: state
        })
        .then(res => {
          if (res.data.success) {
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.getUserList();
          }
        });
    },
    cState(index, obj, state) {
      this.axios
        .post("admin/videoCheckState", {
          id: obj.id,
          state: state
        })
        .then(res => {
          if (res.data.success) {
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.getUserList();
          }
        });
    },
    getUserList() {
      this.axios
        .post("admin/videoList", {
          title: this.title,
          pageNumber: this.pageNumber,
          pageSize: this.pageSize
        })
        .then(res => {
          this.totalRow = res.data.page.totalRow;
          this.tableData = res.data.page.list;
        });
    }
  },
  watch: {
    pageNumber: function() {
      console.log(55);
      this.getUserList();
    }
  },
  mounted: function() {
    this.getUserList();
  }
};
</script>

<style lang="scss" scoped>
.cover-photo {
  height: 45px;
  width: 80px;
}
img {
  height: 100%;
  width: 100%;
}
.pagination {
  margin-top: 20px;
}
</style>